package com.tom.demo.controller.system;

import com.tom.demo.common.annotation.OperaLog;
import com.tom.demo.common.entity.SysDept;
import com.tom.demo.common.enumeration.OperaTypeEnum;
import com.tom.demo.common.response.Result;
import com.tom.demo.dto.DeptDto;
import com.tom.demo.service.system.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = {"部门管理"})
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Resource
    private DeptService deptService;

    @GetMapping("/getDepartment")
    @ApiOperation(value = "获取部门列表信息")
    @PreAuthorize(value = "hasAuthority('system:dept:query')")
    public Result getDepartment(){
        List<SysDept> deptList = deptService.getDepartment();
        return Result.success(deptList);
    }

    @PostMapping("/insertDepartment")
    @ApiOperation(value = "新增部门")
    @PreAuthorize(value = "hasAuthority('system:dept:add')")
    @OperaLog(operaModel = "部门管理",operaType = OperaTypeEnum.ADD,operaDesc = "新增部门")
    public Result insertDepartment(@RequestBody @Validated DeptDto deptDto){
        return deptService.insertDepartment(deptDto);
    }



}
